﻿using System;
using System.Collections.Generic;
//
using CookComputing.XmlRpc;
using PerceptiveMCAPI.Types;
//
namespace PerceptiveMCAPI.Methods
{
   public class campaignNotOpenedAIM : Api_BaseExecute
   {
      private new campaignNotOpenedAIMInput Input { get; set; }
      private campaignNotOpenedAIMOutput Output { get; set; }
      // =============================================== constructors
      public campaignNotOpenedAIM() { }
      // ---------
      public campaignNotOpenedAIM( campaignNotOpenedAIMInput input ) { Input = input; }
      // =============================================== Execute
      public campaignNotOpenedAIMOutput Execute()
      {
         // empty constructor & Execute() is bad
         if ( Input == null )
            throw new ArgumentException( "Input class not provided" );
         // do the deed
         Output = Execute( Input );
         return Output;
      }
      // ---------------------------------------------
      public campaignNotOpenedAIMOutput Execute( campaignNotOpenedAIMInput input )
      {
         Input = input;
         Output = new campaignNotOpenedAIMOutput( Input );
         ValidationIsOK = true;
         //-------------------------
         if ( Input.api_Validate )
         {
            Output.api_ValidatorMessages = ValidateInput.Validate( Input );
            ValidationIsOK = ValidateInput.IsOK( Output.api_ValidatorMessages );
         }
         //------------------------- do it
         if ( ValidationIsOK )
         {
            ApiRun( Input, input.parms.apikey );  // execute API & format output
         }
         // ---
         return Output;
      }

      #region ================================================================= API Calls

      // ---------------------------------------------------------- XmlRpc
      protected override void ExecuteXmlRpc()
      {
         try
         {
            string[] rpcResult = apiXmlRpc.api.campaignNotOpenedAIM( Input.parms.apikey, Input.parms.cid, Input.parms.start, Input.parms.limit );
            Output.Format( rpcResult );
         }
         catch ( XmlRpcFaultException fex )
         {
            Output.api_ErrorMessages.Add( apiException.FormatError( fex ) );
         }
         catch ( Exception ex )
         {
            Output.api_ErrorMessages.Add( apiException.FormatError( ex ) );
         }
      }

      // ---------------------------------------------------------- Serial Post
      protected override void ExecuteSerialPost()
      {
         try
         {
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add( "apikey", Input.parms.apikey );
            dict.Add( "cid", Input.parms.cid );
            dict.Add( "start", Input.parms.start.ToString() );
            dict.Add( "limit", Input.parms.limit.ToString() );
            // -- do it
            string api_Request = "";
            string api_Response = apiSerial.ProcessRequest( Input, dict, out api_Request );
            Output.Format( api_Request, api_Response );
         }
         catch ( Exception ex )
         {
            Output.api_ErrorMessages.Add( apiException.FormatError( ex ) );
         }
      }

      #endregion
   }
}
